using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Localization.Components;
/// <summary>
/// 简易任务引道，玩家按顺序完成指引
/// </summary>
public class TodoListManager : MonoBehaviour
{
    [SerializeField]
    TodoItemSetSO _quests;
    //检查完成条件
    //发布新任务在条件完成后.
    //任务开始时弹出一个提示内容

    [SerializeField]
    List<TextMeshProUGUI> _questText;
    public void RefreshUI()
    {
        var todoItems = _quests.TodoItemSOs;
        //显示ui队列,根据数据的数组中的内容,少于的隐藏,多余的无视
        var maxDisplay = _questText.Count;
        for (int i = 0; i < maxDisplay; i++)
        {
            if(i< todoItems.Count)
            {
                var uiItem = _questText[i];
                var dataItem = todoItems[i];
                var referenceKey = (dataItem as IUiNameDescription).Description;
                if(uiItem.TryGetComponent<LocalizeStringEvent>(out var localizeStringEvent))
                {
                    localizeStringEvent.StringReference.TableEntryReference = referenceKey;
                    if (string.IsNullOrWhiteSpace(referenceKey) || localizeStringEvent == null || localizeStringEvent.StringReference == null || localizeStringEvent.StringReference.IsEmpty)
                    {
                        uiItem.SetText(referenceKey);
                    }
                    else
                    {
 
                        var arg1 = new Dictionary<string, string>(){ { "Count", "1" } };
                        var arg2 = new Dictionary<string, string>() { { "ItemName", "Wood" } };
                        //localizeStringEvent.StringReference.Arguments = new object[] { arg1 };
                        uiItem.SetText(localizeStringEvent.StringReference.GetLocalizedString(arg1,arg2));
                    }
    
                }
          
            }
        }
    }

    private void Update()
    {
        RefreshUI();
    }
}


public interface ITodoItem
{
    /// <summary>
    /// 结束任务,并移除
    /// </summary>
    public void Complete();
}